import { defineStore } from 'pinia'
import { ref } from 'vue'

// 按需导出
export const useUserStore = defineStore(
  'big-user',
  () => {
    const userInfo = ref({
      token: '',
      username: '',
      nickname: ''
    })

    const setUserInfo = (info) => {
      userInfo.value.nickname = info.nickname
      userInfo.value.username = info.username
      userInfo.value.token = info.id
    }
    const removeUserInfo = () => {
      userInfo.value.nickname = ''
      userInfo.value.username = ''
      userInfo.value.token = ''
    }

    return {
      userInfo,
      setUserInfo,
      removeUserInfo
    }
  },
  {
    persist: true,
  },
)
